/*
 * Vent_Combos.java
 *
 * Created on 9 de abril de 2006, 05:30 PM
 */

package administrador;
import javax.swing.*;
import java.sql.*;
import javax.swing.*;

/**
 *
 * @author  User
 */
public class Vent_Combos extends javax.swing.JPanel {
    Conexion conexion;
    Usuario user;
    int bodega;
    /** Creates new form Vent_Combos */
    public Vent_Combos(Conexion cEnt,Usuario user,int bEnt) {
        conexion=cEnt;
        initComponents();
        this.user=user;
        bodega=bEnt;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabla = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txt_nombre = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        bt_crear = new javax.swing.JButton();
        txt_cod2 = new javax.swing.JTextField();
        bt_buscar = new javax.swing.JButton();
        bt_anadir = new javax.swing.JButton();
        bt_sacar = new javax.swing.JButton();
        txt_codigo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txt_cant = new javax.swing.JTextField();
        txt_precio = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txt_nom2 = new javax.swing.JTextField();
        bt_modificar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        txt_tot = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        txt_preci2 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txt_sub = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txt_porDesc = new javax.swing.JTextField();
        txt_desc = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();

        jButton1.setText("jButton1");

        setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jScrollPane2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(198, 196, 196)));
        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "cod_producto", "nombre", "cantidad", "Precio", "Subtotal"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tabla);

        jPanel1.add(jScrollPane2);
        jScrollPane2.setBounds(40, 180, 480, 260);

        jLabel1.setForeground(new java.awt.Color(153, 0, 51));
        jLabel1.setText("Productos:");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(550, 220, 80, 20);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setForeground(new java.awt.Color(0, 153, 255));
        jLabel2.setText("Productos:");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(40, 160, 60, 20);

        jPanel1.add(txt_nombre);
        txt_nombre.setBounds(90, 70, 280, 20);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setForeground(new java.awt.Color(102, 102, 102));
        jLabel3.setText("Nombre:");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(40, 70, 60, 20);

        bt_crear.setFont(new java.awt.Font("Tahoma", 1, 11));
        bt_crear.setForeground(new java.awt.Color(153, 0, 51));
        bt_crear.setText("Crear");
        bt_crear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_crearActionPerformed(evt);
            }
        });

        jPanel1.add(bt_crear);
        bt_crear.setBounds(610, 50, 130, 30);

        txt_cod2.setEditable(false);
        txt_cod2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_cod2KeyTyped(evt);
            }
        });

        jPanel1.add(txt_cod2);
        txt_cod2.setBounds(550, 240, 190, 20);

        bt_buscar.setText("Buscar Producto");
        bt_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_buscarActionPerformed(evt);
            }
        });

        jPanel1.add(bt_buscar);
        bt_buscar.setBounds(620, 200, 120, 30);

        bt_anadir.setFont(new java.awt.Font("Tahoma", 1, 12));
        bt_anadir.setText("<< (+)");
        bt_anadir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_anadirActionPerformed(evt);
            }
        });

        jPanel1.add(bt_anadir);
        bt_anadir.setBounds(550, 380, 80, 23);

        bt_sacar.setFont(new java.awt.Font("Tahoma", 1, 12));
        bt_sacar.setText("(-) >>");
        bt_sacar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_sacarActionPerformed(evt);
            }
        });

        jPanel1.add(bt_sacar);
        bt_sacar.setBounds(550, 410, 80, 23);

        jPanel1.add(txt_codigo);
        txt_codigo.setBounds(90, 100, 130, 20);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel4.setForeground(new java.awt.Color(102, 102, 102));
        jLabel4.setText("Codigo:");
        jPanel1.add(jLabel4);
        jLabel4.setBounds(40, 100, 60, 20);

        jLabel5.setForeground(new java.awt.Color(153, 0, 51));
        jLabel5.setText("Cantidad:");
        jPanel1.add(jLabel5);
        jLabel5.setBounds(620, 350, 80, 20);

        txt_cant.setEditable(false);
        jPanel1.add(txt_cant);
        txt_cant.setBounds(670, 350, 70, 19);

        txt_precio.setText("0.0");
        jPanel1.add(txt_precio);
        txt_precio.setBounds(90, 130, 130, 19);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel6.setForeground(new java.awt.Color(102, 102, 102));
        jLabel6.setText("Precio:");
        jPanel1.add(jLabel6);
        jLabel6.setBounds(40, 130, 60, 20);

        jLabel7.setForeground(new java.awt.Color(153, 0, 51));
        jLabel7.setText("Nombre");
        jPanel1.add(jLabel7);
        jLabel7.setBounds(550, 260, 80, 20);

        txt_nom2.setEditable(false);
        jPanel1.add(txt_nom2);
        txt_nom2.setBounds(550, 280, 190, 20);

        bt_modificar.setFont(new java.awt.Font("Tahoma", 1, 11));
        bt_modificar.setForeground(new java.awt.Color(153, 0, 51));
        bt_modificar.setText("Modificar");
        bt_modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_modificarActionPerformed(evt);
            }
        });

        jPanel1.add(bt_modificar);
        bt_modificar.setBounds(610, 80, 130, 30);

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton2.setForeground(new java.awt.Color(153, 0, 51));
        jButton2.setText("Borrar Combo");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel1.add(jButton2);
        jButton2.setBounds(610, 110, 130, 30);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel8.setForeground(new java.awt.Color(153, 0, 51));
        jLabel8.setText("TOTAL:");
        jPanel1.add(jLabel8);
        jLabel8.setBounds(290, 480, 60, 20);

        txt_tot.setBackground(new java.awt.Color(102, 0, 51));
        txt_tot.setEditable(false);
        txt_tot.setForeground(new java.awt.Color(255, 204, 0));
        txt_tot.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txt_tot.setText("0.0");
        jPanel1.add(txt_tot);
        txt_tot.setBounds(360, 480, 140, 19);

        jButton3.setText("Buscar Combo");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jPanel1.add(jButton3);
        jButton3.setBounds(380, 70, 110, 30);

        jLabel9.setForeground(new java.awt.Color(153, 0, 51));
        jLabel9.setText("Precio:");
        jPanel1.add(jLabel9);
        jLabel9.setBounds(620, 320, 80, 20);

        txt_preci2.setEditable(false);
        jPanel1.add(txt_preci2);
        txt_preci2.setBounds(670, 320, 70, 19);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel10.setText("Subtotal");
        jPanel1.add(jLabel10);
        jLabel10.setBounds(290, 440, 70, 20);

        txt_sub.setEditable(false);
        txt_sub.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txt_sub.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.add(txt_sub);
        txt_sub.setBounds(360, 440, 140, 20);

        jLabel11.setText("Desc.");
        jPanel1.add(jLabel11);
        jLabel11.setBounds(290, 460, 50, 20);

        txt_porDesc.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txt_porDesc.setText("0");
        txt_porDesc.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        txt_porDesc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_porDescKeyTyped(evt);
            }
        });

        jPanel1.add(txt_porDesc);
        txt_porDesc.setBounds(360, 460, 30, 20);

        txt_desc.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txt_desc.setText("0");
        jPanel1.add(txt_desc);
        txt_desc.setBounds(390, 460, 110, 19);

        jButton4.setText("Limpiar Datos");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jPanel1.add(jButton4);
        jButton4.setBounds(380, 100, 110, 30);

        jLabel12.setFont(new java.awt.Font("Stencil", 1, 36));
        jLabel12.setForeground(new java.awt.Color(92, 170, 249));
        jLabel12.setText("Combos");
        jPanel1.add(jLabel12);
        jLabel12.setBounds(40, 10, 180, 45);

        jLabel13.setForeground(new java.awt.Color(153, 0, 0));
        jLabel13.setText("Creacion");
        jPanel1.add(jLabel13);
        jLabel13.setBounds(160, 40, 70, 30);

        add(jPanel1, java.awt.BorderLayout.CENTER);

    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
        limpiar();
        actualizoTotales();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
        BuscadorProducto b=new BuscadorProducto(conexion,this,2,bodega);
    }//GEN-LAST:event_jButton3ActionPerformed

     public void llenoSegunCodigo(String codigo){
         limpioTabla();
         ResultSet resp;
         int contador=0;
            resp=conexion.consultarBase("select * from combo where cod_combo like '"+codigo+"'");
            int filasIn=conexion.obtenerFilas(resp);
            
            if(filasIn>0){
           
            try{
            resp.beforeFirst();
            while(resp.next()){
                
                tabla.setValueAt(resp.getString(2),contador,0);
                tabla.setValueAt(resp.getString(3),contador,1);
                tabla.setValueAt(resp.getInt(4),contador,2);
                tabla.setValueAt(resp.getDouble(5),contador,3);
                
                
                //Calculo el Subtotal:
                int cant=resp.getInt(4);
                double precio=resp.getDouble(5);
                double sub=cant*precio;
                
                tabla.setValueAt(sub,contador,4);
                
                contador++;
            }
        }catch(SQLException sqle){
            System.out.println("Error al mostrar los resultados de la consulta dEl Combo");
            System.err.println(sqle);
        }
                
                
                
            } else {
                JOptionPane.showMessageDialog(this,"El Combo:"+codigo+" no Existe","Informacion",JOptionPane.INFORMATION_MESSAGE);
                limpiar();
                actualizoTotales();
            }
      actualizoTotales();   
     }
    
    private void txt_porDescKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_porDescKeyTyped
// TODO add your handling code here:
        int press=evt.getKeyChar();
        if(press==10){
            actualizoTotales();
        }
    }//GEN-LAST:event_txt_porDescKeyTyped

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
        borroCombo("Seguro Quiere eliminar");
        limpiar();
        
    }//GEN-LAST:event_jButton2ActionPerformed

    public void borroCombo(String frase){
    
    String cod=txt_codigo.getText();
        cod=cod.replaceAll(" ","");
        
        if(cod.equals("")){
            JOptionPane.showMessageDialog(this,"El combo a borrar no fue especificado","Informacion",JOptionPane.INFORMATION_MESSAGE);
            
        }else{
            
            //Verifico si el Combo Existe.
            ResultSet resp;
            resp=conexion.consultarBase("select * from combo where cod_combo like '"+cod+"'");
            int filasIn=conexion.obtenerFilas(resp);
            if(filasIn>0){
            
            int opccion=0;
            opccion=JOptionPane.showConfirmDialog(this,frase+" el Combo cod= "+cod+" ","Alerta",0);
            
            if(opccion==0){   

             //Borro Combo
             conexion.insertarDatos("DELETE FROM producto WHERE cod_producto='"+cod+"'");
             //Borro Articulos del Combo
             conexion.insertarDatos("DELETE FROM combo WHERE cod_combo='"+cod+"'");
            
            }
            
            }else{
            JOptionPane.showMessageDialog(this,"Este combo no existe","Informacion",JOptionPane.INFORMATION_MESSAGE);
            }
        
            }
        }
    
    
    
    private void bt_modificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_modificarActionPerformed
// TODO add your handling code here:
        
        String nomb=txt_nombre.getText();
        double prec=Double.parseDouble(txt_precio.getText());
        String cod=txt_codigo.getText();
        String descripcion=obtieneDesc();
        
        nomb=nomb.replaceAll(" ","");
        cod=cod.replaceAll(" ","");
        
        if(nomb.equals("")||cod.equals("")||prec<0||cuentaProductos()<=0){
            JOptionPane.showMessageDialog(this,"Los Datos del Combo no han Sido LLenados Correctamente o No existen Productos","Informacion",JOptionPane.INFORMATION_MESSAGE);
            
        }else{
        
            //Verifico si el PRodcuto Existe.
            ResultSet resp;
            resp=conexion.consultarBase("select * from producto where cod_producto like '"+cod+"'");
            int filasIn=conexion.obtenerFilas(resp);
            if(filasIn>0){
                
                //Elimio el Combo
                  borroCombo("Seguro Quiere Modificar");
                //Creo el Combo com muevos datos:
                  creoCombo();
                 
            } else {
              JOptionPane.showMessageDialog(this,"El Combo"+nomb+" No fue Creado:","Informacion",JOptionPane.INFORMATION_MESSAGE);    
            }
        
                            
        
        
        }
    }//GEN-LAST:event_bt_modificarActionPerformed

    private void bt_sacarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_sacarActionPerformed
// TODO add your handling code here:
        int filaSeleccionada=tabla.getSelectedRow();
        System.out.println("La fila seleccionada es "+filaSeleccionada);
        if(filaSeleccionada==-1){
         JOptionPane.showMessageDialog(this,"Seleccione una fila para poder Borrarla","Informacion",JOptionPane.INFORMATION_MESSAGE);
        }
        else{
        limpiarFila(filaSeleccionada);
        
        }
        actualizoTotales();
        
    }//GEN-LAST:event_bt_sacarActionPerformed

        public void limpioTabla(){
    //limpio tabla:
        for(int i=0;i<tabla.getRowCount();i++){
            
            try{
                String valor=tabla.getValueAt(i,0).toString();
                valor=valor.replaceAll(" ","");
                if(valor==null||valor==""){
                   
                }else{
                limpiarFila(i);
                }
            }catch(java.lang.NullPointerException en){
                
            }
    }
    }
    
    public void limpiar(){
    //limpio tabla:
    limpioTabla();
        
    //Limpio cuadros de texto:  
       txt_cant.setText(""); 
       txt_cod2.setText("");
       txt_codigo.setText("");
       txt_nom2.setText("");
       txt_nombre.setText("");
       txt_precio.setText("");
    }
    
    public void limpiarFila(int fila){
    tabla.setValueAt("",fila,0);
    tabla.setValueAt("",fila,1);
    tabla.setValueAt("",fila,2);
    tabla.setValueAt("",fila,3);
    tabla.setValueAt("",fila,4);
    }
    
    private void txt_cod2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_cod2KeyTyped
// TODO add your handling code here:
        txt_cant.setEditable(true);
        
    }//GEN-LAST:event_txt_cod2KeyTyped

    private void bt_anadirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_anadirActionPerformed
// TODO add your handling code here:
        String nombrePro=txt_nom2.getText();
        String cantPro=txt_cant.getText();
        String codigo=txt_cod2.getText();
        String precio=txt_preci2.getText();
        
        nombrePro=nombrePro.replaceAll(" ", "");
        cantPro=cantPro.replaceAll(" ","");
        if(nombrePro.equals("")||cantPro.equals("")||precio.equals("")){
          JOptionPane.showMessageDialog(this,"Llena los datos del Precio, Nombre y Cantidad","Informacion",JOptionPane.INFORMATION_MESSAGE);
          
        }else{
        int libre=buscaVacio();    
        tabla.setValueAt(codigo,libre,0);
        tabla.setValueAt(nombrePro,libre,1);
        tabla.setValueAt(cantPro,libre,2);
        tabla.setValueAt(precio,libre,3);
        
        //Calculo el Subtotal:
        try{
        int cant=Integer.parseInt(cantPro);
        double prec=Double.parseDouble(precio);
        double resp=cant*prec;
        
        resp=Math.abs(resp*100);
        resp=resp/100;
        
        
        tabla.setValueAt(resp,libre,4);
        }
        catch(Exception e){
        System.out.println("Error en Cambio Formato");
        }
        
        actualizoTotales();
        
        }
        
    }//GEN-LAST:event_bt_anadirActionPerformed
   
    public void actualizoTotales(){
        // System.out.println("Entra en actualiza");
        int numeroCol=tabla.getRowCount();
        int cont=0;
        double acumula=0;
        String toma;
        
        //Muestro Los Subtotales:
        while (cont<numeroCol){
            
            try{
                toma=tabla.getValueAt(cont, 4).toString();
                acumula=acumula+Double.parseDouble(toma);
            } catch(Exception e){};
            cont++;
        }
        
        
        acumula=Math.abs(acumula*100);
        acumula=acumula/100;
        
        txt_sub.setText(String.valueOf(acumula));
        
       //Muestro el Descuento
        int porcentaje=Integer.parseInt(txt_porDesc.getText());
        double descuento=0;
        descuento=(acumula*porcentaje)/100;
        txt_desc.setText(String.valueOf(descuento));
        
        //Muestro Total:
        double total=(acumula-descuento);
        total=Math.abs(total*100);
        total=total/100;
        txt_tot.setText(String.valueOf(total));
        
        
        
    }
    
    
    
    public int buscaVacio(){
        int verific=0;
        
        for(int i=0;i<tabla.getRowCount();i++){
            
            try{
                String valor=tabla.getValueAt(i,0).toString();
                valor=valor.replaceAll(" ","");
                if(valor==null||valor==""){
                    verific=i;
                    break;
                }
            }catch(java.lang.NullPointerException en){
                verific=i;
                break;
            }
            
            
            
        }
        return verific;
    }
    
    
    private void bt_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_buscarActionPerformed
// TODO add your handling code here:
         BuscadorProducto b=new BuscadorProducto(conexion,this,1,bodega);
    }//GEN-LAST:event_bt_buscarActionPerformed

    private void bt_crearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_crearActionPerformed
// TODO add your handling code here:
        creoCombo();
    }//GEN-LAST:event_bt_crearActionPerformed
    
    public void creoCombo(){
        String nomb=txt_nombre.getText();
        double prec=Double.parseDouble(txt_precio.getText());
        String cod=txt_codigo.getText();
        String descripcion=obtieneDesc();
        
        nomb=nomb.replaceAll(" ","");
        cod=cod.replaceAll(" ","");
        
        if(nomb.equals("")||cod.equals("")||prec<0||cuentaProductos()<=0){
            JOptionPane.showMessageDialog(this,"Los Datos del Combo no han Sido LLenados Correctamente o No existen Productos","Informacion",JOptionPane.INFORMATION_MESSAGE);
            
        }else{
            
            //Accion de Modificar Producto:
            //Verifico si el Producto Existe.
            ResultSet resp;
            resp=conexion.consultarBase("select * from producto where cod_producto like '"+cod+"'");
            int filasIn=conexion.obtenerFilas(resp);
            if(filasIn>0){
                JOptionPane.showMessageDialog(this,"El Combo:"+nomb+" ya fue Creado:","Informacion",JOptionPane.INFORMATION_MESSAGE);
            } else {
                
                
                //Creo el nuevo Combo:
                //System.out.println("Inserto producto:"+cod+"',"+24+",'"+nomb+"','"+descripcion+"',"+0+","+prec+","+5);
                String fecha=new java.sql.Date(System.currentTimeMillis()).toString();
        
                conexion.insertarDatos("insert into producto values('"+cod+"',"+18+",'"+nomb+"','"+descripcion+"',"+1+","+prec+","+5+",'"+fecha+"')");
                //Ingreso los productos del Combo:
                
                for(int i=0;i<tabla.getRowCount();i++){
                    
                    try{
                        String valor=tabla.getValueAt(i,0).toString();
                        valor=valor.replaceAll(" ","");
                        if(valor==null||valor==""){
                            
                        }else{
                            //System.out.println("El producto["+i+"]:"+tabla.getValueAt(i,0).toString()+" "+tabla.getValueAt(i,1).toString()+" "+tabla.getValueAt(i,2).toString());
                            conexion.insertarDatos("insert into combo values('"+cod+"','"+tabla.getValueAt(i,0).toString()+"','"+tabla.getValueAt(i,1).toString()+"',"+tabla.getValueAt(i,2).toString()+","+tabla.getValueAt(i,3).toString()+")");
                            
                        }
                        
                    }catch(java.lang.NullPointerException en){
                        
                    }
                }
                
                
            }
            
           
        }
    }
    
    
    public String obtieneDesc(){
    String concat="";
           for(int i=0;i<tabla.getRowCount();i++){
            
            try{
                
                String valor=tabla.getValueAt(i,0).toString();
                valor=valor.replaceAll(" ","");
                if(valor==null||valor==""){
                    
                }else{
                     String cod_pro=tabla.getValueAt(i,0).toString();
                     String nom_pro=tabla.getValueAt(i,1).toString();
                     String cant=tabla.getValueAt(i,2).toString();
                     concat=concat+cod_pro+" "+nom_pro+" "+cant+" \n";
                }
                
            }catch(java.lang.NullPointerException en){
                
            }
        }
        
        return concat;
    }
    
    
    
    public int cuentaProductos(){
        int verific=0;
        
        for(int i=0;i<tabla.getRowCount();i++){
            
            try{
                String valor=tabla.getValueAt(i,0).toString();
                valor=valor.replaceAll(" ","");
                if(valor==null||valor==""){
                    
                }else{
                    verific++;
                }
                
            }catch(java.lang.NullPointerException en){
                
            }
        }
        return verific;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_anadir;
    private javax.swing.JButton bt_buscar;
    private javax.swing.JButton bt_crear;
    private javax.swing.JButton bt_modificar;
    private javax.swing.JButton bt_sacar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tabla;
    public javax.swing.JTextField txt_cant;
    public javax.swing.JTextField txt_cod2;
    public javax.swing.JTextField txt_codigo;
    private javax.swing.JTextField txt_desc;
    public javax.swing.JTextField txt_nom2;
    public javax.swing.JTextField txt_nombre;
    private javax.swing.JTextField txt_porDesc;
    public javax.swing.JTextField txt_preci2;
    public javax.swing.JTextField txt_precio;
    private javax.swing.JTextField txt_sub;
    private javax.swing.JTextField txt_tot;
    // End of variables declaration//GEN-END:variables
    
}
